#####################################
##REPLICATION FOR MCGHEE, ET AL.,####
##"A PRIMARY CAUSE OF PARTISANSHIP"##
#####################################

##Table A3 (Appendix)##

#Load Data#
library(foreign)
library(Zelig)
library(sandwich)
setwd("XXXX") #ENTER DIRECTORY PATHNAME IN PLACE OF XXXX

legyrd <- read.csv("legislator primaries.dem.csv", header=TRUE)
legyrr <- read.csv("legislator primaries.rep.csv", header=TRUE)

#generate election year counter#
legyrd$yrcnt <- (legyrd$elec-1992)/2
legyrr$yrcnt <- (legyrr$elec-1992)/2

#drop ideowt var, which is not used for this table#
legyrd$ideowt <- NULL
legyrr$ideowt <- NULL

#drop missing data#
legyrd <- na.omit(legyrd)
legyrr <- na.omit(legyrr)

#mean-deviate the presidential vote#
legyrd$pvtmn <- legyrd$pvote - mean(legyrd$pvote)
legyrr$pvtmn <- legyrr$pvote - mean(legyrr$pvote)

#define years & states as factors for FE regression#
legyrd$icpsrst <- as.factor(legyrd$icpsrst)
legyrd$yr.dum1 <- as.integer(legyrd$yrcnt==1)
legyrd$yr.dum2 <- as.integer(legyrd$yrcnt==2)
legyrd$yr.dum3 <- as.integer(legyrd$yrcnt==3)
legyrd$yr.dum4 <- as.integer(legyrd$yrcnt==4)
legyrd$yr.dum5 <- as.integer(legyrd$yrcnt==5)
legyrd$yr.dum6 <- as.integer(legyrd$yrcnt==6)
legyrd$yr.dum7 <- as.integer(legyrd$yrcnt==7)
legyrd$yr.dum8 <- as.integer(legyrd$yrcnt==8)
legyrd$yr.dum9 <- as.integer(legyrd$yrcnt==9)
legyrd$yrcnt2 <- as.factor(legyrd$yrcnt)
legyrr$icpsrst <- as.factor(legyrr$icpsrst)
legyrr$yr.dum1 <- as.integer(legyrr$yrcnt==1)
legyrr$yr.dum2 <- as.integer(legyrr$yrcnt==2)
legyrr$yr.dum3 <- as.integer(legyrr$yrcnt==3)
legyrr$yr.dum4 <- as.integer(legyrr$yrcnt==4)
legyrr$yr.dum5 <- as.integer(legyrr$yrcnt==5)
legyrr$yr.dum6 <- as.integer(legyrr$yrcnt==6)
legyrr$yr.dum7 <- as.integer(legyrr$yrcnt==7)
legyrr$yr.dum8 <- as.integer(legyrr$yrcnt==8)
legyrr$yr.dum9 <- as.integer(legyrr$yrcnt==9)
legyrr$yrcnt2 <- as.factor(legyrr$yrcnt)

#Democrats#
z.out <- zelig(pred_np ~ semicl + semiop + open + nonpart + 
	yrcnt + I(yrcnt*semicl) + I(yrcnt*semiop) + I(yrcnt*open) + 
	I(yrcnt*nonpart) + pvtmn + icpsrst + yr.dum1 + yr.dum2 + yr.dum3 +
	yr.dum4 + yr.dum5 + yr.dum6 + yr.dum7 + yr.dum8, 
	model="ls", robust=list(method="vcovHAC"), data=as.data.frame(legyrd))
summary(z.out)
length(legyrd$icpsrst)
x.out0 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=1)
s.cl.d <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=1, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=1, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=1)
s.scl.d <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=0, semiop=1, open=0, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=1, open=0, nonpart=0, pvtmn=0, yrcnt=1)
s.sop.d <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=0, semiop=0, open=1, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=0, open=1, nonpart=0, pvtmn=0, yrcnt=1)
s.op.d <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=1, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=1, pvtmn=0, yrcnt=1)
s.np.d <- sim(z.out, x=x.out0, x1=x.out1)

#Republicans#
z.out <- zelig(pred_np ~ semicl + semiop + open + nonpart + 
	yrcnt + I(yrcnt*semicl) + I(yrcnt*semiop) + I(yrcnt*open) + 
	I(yrcnt*nonpart) + pvtmn + icpsrst + yr.dum1 + yr.dum2 + yr.dum3 +
	yr.dum4 + yr.dum5 + yr.dum6 + yr.dum7 + yr.dum8, 
	model="ls", robust=list(method="vcovHAC"), data=as.data.frame(legyrr))
summary(z.out)
length(legyrr$icpsrst)
x.out0 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=1)
s.cl.r <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=1, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=1, semiop=0, open=0, nonpart=0, pvtmn=0, yrcnt=1)
s.scl.r <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=0, semiop=1, open=0, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=1, open=0, nonpart=0, pvtmn=0, yrcnt=1)
s.sop.r <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=0, semiop=0, open=1, nonpart=0, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=0, open=1, nonpart=0, pvtmn=0, yrcnt=1)
s.op.r <- sim(z.out, x=x.out0, x1=x.out1)
x.out0 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=1, pvtmn=0, yrcnt=0)
x.out1 <- setx(z.out, semicl=0, semiop=0, open=0, nonpart=1, pvtmn=0, yrcnt=1)
s.np.r <- sim(z.out, x=x.out0, x1=x.out1)

##Figure 3##
close.screen(all.screens=TRUE)
#Closed: Dem
par(cex.axis=.8, cex.lab=.8, font.axis=6, lheight=.5, mar=c(1,3,1.5,.5), mgp=c(1,.6,0),
	fig=c(0,.36,.55,.98), new=TRUE)
closed.d <- array(c(mean(s.cl.d$qi$pv1), mean(s.cl.d$qi$pv1)+mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+2*mean(s.cl.d$qi$fd), 
	mean(s.cl.d$qi$pv1)+3*mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+4*mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+5*mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+6*mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+7*mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+8*mean(s.cl.d$qi$fd),
	mean(s.cl.d$qi$pv1)+9*mean(s.cl.d$qi$fd)))
year <- array(c(1992, 1994, 1996, 1998, 2000, 2002, 2004, 2006, 2008, 2010))
plot(year, closed.d, type="l", lty="dashed", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
closed.d.p <- array(c(mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+2*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)), 
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+3*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+4*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+5*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+6*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+7*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+8*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)+2*apply(s.cl.d$qi$pv1, 2, sd)+9*(mean(s.cl.d$qi$fd)+2*apply(s.cl.d$qi$fd, 2, sd))))
lines(year, closed.d.p, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
closed.d.m <- array(c(mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+2*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)), 
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+3*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+4*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+5*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+6*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+7*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+8*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd)),
	mean(s.cl.d$qi$pv1)-2*apply(s.cl.d$qi$pv1, 2, sd)+9*(mean(s.cl.d$qi$fd)-2*apply(s.cl.d$qi$fd, 2, sd))))
lines(year, closed.d.m, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
#Closed: Rep
closed.r <- array(c(mean(s.cl.r$qi$pv1), mean(s.cl.r$qi$pv1)+mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+2*mean(s.cl.r$qi$fd), 
	mean(s.cl.r$qi$pv1)+3*mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+4*mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+5*mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+6*mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+7*mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+8*mean(s.cl.r$qi$fd),
	mean(s.cl.r$qi$pv1)+9*mean(s.cl.r$qi$fd)))
lines(year, closed.r, type="l", lty="solid", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
closed.r.p <- array(c(mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+2*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)), 
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+3*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+4*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+5*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+6*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+7*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+8*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)+2*apply(s.cl.r$qi$pv1, 2, sd)+9*(mean(s.cl.r$qi$fd)+2*apply(s.cl.r$qi$fd, 2, sd))))
lines(year, closed.r.p, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
closed.r.m <- array(c(mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+2*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)), 
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+3*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+4*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+5*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+6*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+7*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+8*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd)),
	mean(s.cl.r$qi$pv1)-2*apply(s.cl.r$qi$pv1, 2, sd)+9*(mean(s.cl.r$qi$fd)-2*apply(s.cl.r$qi$fd, 2, sd))))
lines(year, closed.r.m, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
abline(h=0, lty="solid")
title(main="Pure Closed", font.main=7, cex=1.5)
mtext("Predicted Ideal Point", side=2, line=1.8, cex=1.5, at=c(-2.0), font=7)
text(1993,1.2,"Republicans", cex=.95, adj=c(0,0), font=6)
text(1993,-1.2,"Democrats", cex=.95, adj=c(0,1), font=6)
#Semi-closed: Dem
par(cex.axis=.8, cex.lab=.8, font.axis=6, lheight=.5, mar=c(1,1.5,1.5,.5), mgp=c(1,.6,0),
	fig=c(.36,.68,.55,.98), new=TRUE)
semiclosed.d <- array(c(mean(s.scl.d$qi$pv1), mean(s.scl.d$qi$pv1)+mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+2*mean(s.scl.d$qi$fd), 
	mean(s.scl.d$qi$pv1)+3*mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+4*mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+5*mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+6*mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+7*mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+8*mean(s.scl.d$qi$fd),
	mean(s.scl.d$qi$pv1)+9*mean(s.scl.d$qi$fd)))
plot(year, semiclosed.d, type="l", lty="dashed", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
semiclosed.d.p <- array(c(mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+2*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)), 
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+3*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+4*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+5*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+6*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+7*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+8*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)+2*apply(s.scl.d$qi$pv1, 2, sd)+9*(mean(s.scl.d$qi$fd)+2*apply(s.scl.d$qi$fd, 2, sd))))
lines(year, semiclosed.d.p, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
semiclosed.d.m <- array(c(mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+2*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)), 
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+3*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+4*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+5*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+6*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+7*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+8*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd)),
	mean(s.scl.d$qi$pv1)-2*apply(s.scl.d$qi$pv1, 2, sd)+9*(mean(s.scl.d$qi$fd)-2*apply(s.scl.d$qi$fd, 2, sd))))
lines(year, semiclosed.d.m, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
#Semi-closed: Rep
semiclosed.r <- array(c(mean(s.scl.r$qi$pv1), mean(s.scl.r$qi$pv1)+mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+2*mean(s.scl.r$qi$fd), 
	mean(s.scl.r$qi$pv1)+3*mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+4*mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+5*mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+6*mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+7*mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+8*mean(s.scl.r$qi$fd),
	mean(s.scl.r$qi$pv1)+9*mean(s.scl.r$qi$fd)))
lines(year, semiclosed.r, type="l", lty="solid", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
semiclosed.r.p <- array(c(mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+2*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)), 
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+3*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+4*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+5*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+6*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+7*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+8*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)+2*apply(s.scl.r$qi$pv1, 2, sd)+9*(mean(s.scl.r$qi$fd)+2*apply(s.scl.r$qi$fd, 2, sd))))
lines(year, semiclosed.r.p, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
semiclosed.r.m <- array(c(mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+2*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)), 
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+3*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+4*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+5*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+6*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+7*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+8*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd)),
	mean(s.scl.r$qi$pv1)-2*apply(s.scl.r$qi$pv1, 2, sd)+9*(mean(s.scl.r$qi$fd)-2*apply(s.scl.r$qi$fd, 2, sd))))
lines(year, semiclosed.r.m, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
abline(h=0, lty="solid")
title(main="Semi-closed", font.main=7, cex=1.5)
text(1993,1.2,"Republicans", cex=.95, adj=c(0,0), font=6)
text(1993,-1.2,"Democrats", cex=.95, adj=c(0,1), font=6)
#Semi-open: Dem
par(cex.axis=.8, cex.lab=.8, font.axis=6, lheight=.5, mar=c(1,1.5,1.5,.5), mgp=c(1,.6,0),
	fig=c(.68,.99,.55,.98), new=TRUE)
semiopen.d <- array(c(mean(s.sop.d$qi$pv1), mean(s.sop.d$qi$pv1)+mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+2*mean(s.sop.d$qi$fd), 
	mean(s.sop.d$qi$pv1)+3*mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+4*mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+5*mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+6*mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+7*mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+8*mean(s.sop.d$qi$fd),
	mean(s.sop.d$qi$pv1)+9*mean(s.sop.d$qi$fd)))
year <- array(c(1992, 1994, 1996, 1998, 2000, 2002, 2004, 2006, 2008, 2010))
plot(year, semiopen.d, type="l", lty="dashed", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
semiopen.d.p <- array(c(mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+2*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)), 
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+3*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+4*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+5*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+6*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+7*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+8*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)+2*apply(s.sop.d$qi$pv1, 2, sd)+9*(mean(s.sop.d$qi$fd)+2*apply(s.sop.d$qi$fd, 2, sd))))
lines(year, semiopen.d.p, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
semiopen.d.m <- array(c(mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+2*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)), 
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+3*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+4*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+5*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+6*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+7*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+8*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd)),
	mean(s.sop.d$qi$pv1)-2*apply(s.sop.d$qi$pv1, 2, sd)+9*(mean(s.sop.d$qi$fd)-2*apply(s.sop.d$qi$fd, 2, sd))))
lines(year, semiopen.d.m, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
#Semi-open: Rep
semiopen.r <- array(c(mean(s.sop.r$qi$pv1), mean(s.sop.r$qi$pv1)+mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+2*mean(s.sop.r$qi$fd), 
	mean(s.sop.r$qi$pv1)+3*mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+4*mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+5*mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+6*mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+7*mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+8*mean(s.sop.r$qi$fd),
	mean(s.sop.r$qi$pv1)+9*mean(s.sop.r$qi$fd)))
lines(year, semiopen.r, type="l", lty="solid", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
semiopen.r.p <- array(c(mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+2*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)), 
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+3*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+4*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+5*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+6*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+7*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+8*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)+2*apply(s.sop.r$qi$pv1, 2, sd)+9*(mean(s.sop.r$qi$fd)+2*apply(s.sop.r$qi$fd, 2, sd))))
lines(year, semiopen.r.p, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
semiopen.r.m <- array(c(mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+2*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)), 
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+3*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+4*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+5*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+6*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+7*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+8*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd)),
	mean(s.sop.r$qi$pv1)-2*apply(s.sop.r$qi$pv1, 2, sd)+9*(mean(s.sop.r$qi$fd)-2*apply(s.sop.r$qi$fd, 2, sd))))
lines(year, semiopen.r.m, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
abline(h=0, lty="solid")
title(main="Semi-open", font.main=7, cex=1.5)
text(1993,1.2,"Republicans", cex=.95, adj=c(0,0), font=6)
text(1993,-1.2,"Democrats", cex=.95, adj=c(0,1), font=6)
#Open: Dem
par(cex.axis=.8, cex.lab=.8, font.axis=6, lheight=.5, mar=c(1,3,1.5,.5), mgp=c(1,.6,0),
	fig=c(0,.36,.1,.53), new=TRUE)
open.d <- array(c(mean(s.op.d$qi$pv1), mean(s.op.d$qi$pv1)+mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+2*mean(s.op.d$qi$fd), 
	mean(s.op.d$qi$pv1)+3*mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+4*mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+5*mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+6*mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+7*mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+8*mean(s.op.d$qi$fd),
	mean(s.op.d$qi$pv1)+9*mean(s.op.d$qi$fd)))
plot(year, open.d, type="l", lty="dashed", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
open.d.p <- array(c(mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+2*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)), 
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+3*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+4*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+5*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+6*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+7*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+8*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)+2*apply(s.op.d$qi$pv1, 2, sd)+9*(mean(s.op.d$qi$fd)+2*apply(s.op.d$qi$fd, 2, sd))))
lines(year, open.d.p, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
open.d.m <- array(c(mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+2*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)), 
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+3*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+4*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+5*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+6*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+7*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+8*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd)),
	mean(s.op.d$qi$pv1)-2*apply(s.op.d$qi$pv1, 2, sd)+9*(mean(s.op.d$qi$fd)-2*apply(s.op.d$qi$fd, 2, sd))))
lines(year, open.d.m, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
#Open: Rep
open.r <- array(c(mean(s.op.r$qi$pv1), mean(s.op.r$qi$pv1)+mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+2*mean(s.op.r$qi$fd), 
	mean(s.op.r$qi$pv1)+3*mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+4*mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+5*mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+6*mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+7*mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+8*mean(s.op.r$qi$fd),
	mean(s.op.r$qi$pv1)+9*mean(s.op.r$qi$fd)))
lines(year, open.r, type="l", lty="solid", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
open.r.p <- array(c(mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+2*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)), 
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+3*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+4*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+5*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+6*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+7*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+8*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)+2*apply(s.op.r$qi$pv1, 2, sd)+9*(mean(s.op.r$qi$fd)+2*apply(s.op.r$qi$fd, 2, sd))))
lines(year, open.r.p, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
open.r.m <- array(c(mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+2*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)), 
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+3*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+4*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+5*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+6*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+7*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+8*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd)),
	mean(s.op.r$qi$pv1)-2*apply(s.op.r$qi$pv1, 2, sd)+9*(mean(s.op.r$qi$fd)-2*apply(s.op.r$qi$fd, 2, sd))))
lines(year, open.r.m, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
abline(h=0, lty="solid")
title(main="Pure Open", font.main=7, cex=1.5)
text(1993,1.2,"Republicans", cex=.95, adj=c(0,0), font=6)
text(1993,-1.2,"Democrats", cex=.95, adj=c(0,1), font=6)
#Nonpartisan: Dem
par(cex.axis=.8, cex.lab=.8, font.axis=6, lheight=.5, mar=c(1,1.5,1.5,.5), mgp=c(1,.6,0),
	fig=c(.36,.68,.1,.53), new=TRUE)
nonpartisan.d <- array(c(mean(s.np.d$qi$pv1), mean(s.np.d$qi$pv1)+mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+2*mean(s.np.d$qi$fd), 
	mean(s.np.d$qi$pv1)+3*mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+4*mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+5*mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+6*mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+7*mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+8*mean(s.np.d$qi$fd),
	mean(s.np.d$qi$pv1)+9*mean(s.np.d$qi$fd)))
plot(year, nonpartisan.d, type="l", lty="dashed", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
nonpartisan.d.p <- array(c(mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+2*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)), 
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+3*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+4*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+5*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+6*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+7*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+8*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)+2*apply(s.np.d$qi$pv1, 2, sd)+9*(mean(s.np.d$qi$fd)+2*apply(s.np.d$qi$fd, 2, sd))))
lines(year, nonpartisan.d.p, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
nonpartisan.d.m <- array(c(mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+2*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)), 
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+3*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+4*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+5*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+6*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+7*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+8*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd)),
	mean(s.np.d$qi$pv1)-2*apply(s.np.d$qi$pv1, 2, sd)+9*(mean(s.np.d$qi$fd)-2*apply(s.np.d$qi$fd, 2, sd))))
lines(year, nonpartisan.d.m, type="l", lty="dashed", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
#Nonpartisan: Rep
nonpartisan.r <- array(c(mean(s.np.r$qi$pv1), mean(s.np.r$qi$pv1)+mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+2*mean(s.np.r$qi$fd), 
	mean(s.np.r$qi$pv1)+3*mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+4*mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+5*mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+6*mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+7*mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+8*mean(s.np.r$qi$fd),
	mean(s.np.r$qi$pv1)+9*mean(s.np.r$qi$fd)))
lines(year, nonpartisan.r, type="l", lty="solid", lwd=2, ylim=c(-1.5, 1.5),
		xlab="", ylab="", lab=c(8,5,4))
nonpartisan.r.p <- array(c(mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+2*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)), 
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+3*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+4*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+5*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+6*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+7*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+8*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)+2*apply(s.np.r$qi$pv1, 2, sd)+9*(mean(s.np.r$qi$fd)+2*apply(s.np.r$qi$fd, 2, sd))))
lines(year, nonpartisan.r.p, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
nonpartisan.r.m <- array(c(mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+2*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)), 
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+3*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+4*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+5*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+6*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+7*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+8*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd)),
	mean(s.np.r$qi$pv1)-2*apply(s.np.r$qi$pv1, 2, sd)+9*(mean(s.np.r$qi$fd)-2*apply(s.np.r$qi$fd, 2, sd))))
lines(year, nonpartisan.r.m, type="l", lty="solid", ylim=c(-1.5, 1.5),
	xlab="", ylab="", lab=c(8,5,4), col="gray")
abline(h=0, lty="solid")
title(main="Nonpartisan", font.main=7, cex=1.5)
text(1993,1.2,"Republicans", cex=.95, adj=c(0,0), font=6)
text(1993,-1.2,"Democrats", cex=.95, adj=c(0,1), font=6)


